* Table 4

* Load MSD9919 dataset

* Create Table 4:Candidate Performance and Ministerial Appointment
eststo clear
logistic min votemargin, vce(cluster id) coef
eststo
logistic min votemargin i.ls, vce(cluster id) coef
eststo
logistic min votemargin i.ls p_exp min_exp la_exp cmin_exp scab_exp, vce(cluster id) coef
eststo
logistic min votemargin i.ls gender age bachelors, vce(cluster id) coef
eststo
esttab using Table4.csv, replace compress aic scalars("ll Log lik") b(%9.3f) se(%9.3f)


*Figure 1
logistic min votemargin i.ls p_exp min_exp la_exp cmin_exp scab_exp, vce(cluster id) coef
margins, at(votemargin=(0(10)60)) atmeans vsquish post

**************************************************************************
*Graph Settings
net install http://www.stata-journal.com/software/sj18-3/gr0073/
ssc install grstyle, replace
ssc install palettes, replace

grstyle clear
set scheme s2color
grstyle init
grstyle set plain, box
grstyle color background white
grstyle set color Set1
grstyle yesno draw_major_hgrid yes
grstyle yesno draw_major_ygrid yes
grstyle color major_grid gs8
grstyle linepattern major_grid dot
grstyle set legend 4, box inside
grstyle color ci_area gs12%50
**************************************************************************

marginsplot, recast(line) plot1opts(lcolor(gs8)) ciopt(color(black%20)) recastci(rarea) title("Figure 1. Electoral Success and Ministerial Appointment") xtitle("Winning Vote Margin (%)") ytitle("Predicted Probability of Ministerial Appointment") name(diff5)


* Create Table 5: First Ministerial Appointment
* This follows on from the use of the same dataset above.  If you have not loaded the MSD9919 dataset, do so now.

keep if min_exp==0
eststo clear
logistic min votemargin i.ls p_exp la_exp cmin_exp scab_exp, vce(cluster id) coef
eststo
logistic min votemargin i.ls gender age bachelors, vce(cluster id) coef
eststo
esttab using Table5.csv, replace compress aic scalars("ll Log lik") b(%9.3f) se(%9.3f)
